package com.robot.member.controller;

import com.alibaba.fastjson.JSON;
import com.robot.member.client.MerchantClient;
import com.robot.member.client.OrdersClient;
import com.robot.member.pojo.Evaluate;
import com.robot.member.service.EvaluateService;
import com.robot.member.service.MemberService;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * evaluate控制器层
 *
 * @author wuyunbin
 */
@RestController
@CrossOrigin
@RequestMapping("/evaluate")
public class EvaluateJsonController {

    @Autowired
    private EvaluateService evaluateService;
    @Autowired
    private MemberService memberService;

    @Autowired
    private HttpServletRequest request;


    @Autowired
    private MerchantClient merchantClient;
    @Autowired
    private OrdersClient ordersClient;

    /**
     * 根据storeId查店铺下所有评价并分页
     *
     * @param storeId
     * @param page
     * @param size
     * @return
     */
    @GetMapping(value = "third/findEvaluatesByStoreId/{storeId}/{page}/{size}", produces = "application/json; charset=utf-8")
    public String thirdFindEvaluatesByStoreId(@PathVariable String storeId, @PathVariable int page, @PathVariable int size) {
        Page<Evaluate> pageData = evaluateService.findAllByStoreIdAndDeletedAtIsNullOrderByCreatedAtDesc(storeId, page, size);
        PageResult<Evaluate> pageResult = new PageResult<>(pageData.getTotalElements(), pageData.getContent());
        return JSON.toJSONString(pageResult);
    }
}
